package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.BisNurseTypeService;
import com.sykj.manage.model.BisNurseType;
import com.sykj.util.IDGenerator;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;

@Controller
@RequestMapping("/bnt")
public class BisNurseTypeController {

	@Autowired
	BisNurseTypeService bisNurseTypeService;
	
	@RequestMapping("/type")
	@ResponseBody
	public ManageBody getAll(BisNurseType bisNurseType,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize), pageSize==null?10:pageSize, true);
		List<BisNurseType> getAll = bisNurseTypeService.getAll(bisNurseType);
		PageInfo<BisNurseType> pageInfo = new PageInfo<BisNurseType>(getAll);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public ManageBody add(BisNurseType bisNurseType){
		bisNurseType.setModify_time(new Date());
		bisNurseType.setType_id(IDGenerator.generatorId());
		int add = bisNurseTypeService.add(bisNurseType);
		if (add>0) {
			System.out.println("=========================================="+bisNurseType);
			return ManageBody.getData(1, add, "");
		} else {
			return ManageBody.getData(1, add, "");
		}
	}
	
	@RequestMapping("/deleteType/{type_id}")
	@ResponseBody
	public ManageBody deleteType(@PathVariable("type_id")String type_id){
		int deleteType = bisNurseTypeService.deleteType(type_id);
		if (deleteType>0) {
			System.out.println("删除了"+deleteType+"数据，Id是："+type_id);
			return ManageBody.getData(1, deleteType, "");
		} else {
			return ManageBody.getData(1, deleteType, "");
		}
	}
	
	//id查询
		@RequestMapping("/findByTypeId/{type_id}")
		@ResponseBody
		public ManageBody Info(@PathVariable("type_id") String type_id ){
			//根据id获取所选对象数据
			BisNurseType findByTypeId = bisNurseTypeService.findByTypeId(type_id);
			return ManageBody.getData(1, findByTypeId, "");
		}
	
	//修改
	@RequestMapping("/updateType")
	@ResponseBody
	public ManageBody updateType(BisNurseType bisNurseType){
	   bisNurseType.setModify_time(new Date());
	   int updateType = bisNurseTypeService.updateType(bisNurseType);
	   if (updateType>0) {
			System.out.println("====================修改了"+updateType);
			return ManageBody.getData(1, updateType, "");
		} else {
			return ManageBody.getData(1, updateType, "");
		}
		
	}
}
